package dao;

import java.sql.ResultSet;

import model.UsersModel;

public class UsersDao {

	public int register(UsersModel model){
		String sql = "insert into users(username,userpass,usertel,headerimage) values(?,?,?,?)";
		Object[] values = new Object[]{model.getUsername(),model.getUserpass(),model.getUsertel(),model.getHeaderimage(),};
		DBHelper helper = new DBHelper();
		int i = helper.executeUpdate(sql,values);
		return i;
	}
	
	
	public UsersModel login(String username, String userpass){
		UsersModel model = null;
		String sql = "select * from users where username=? and userpass=?";
		Object[] values = new Object[]{username,userpass};
		DBHelper helper = new DBHelper();
		ResultSet rs = helper.executeQuery(sql,values);
		
		try {
			while(rs.next()){
				model = new UsersModel();
				model.setUsername(rs.getString("username"));
				model.setUserpass(rs.getString("userpass"));
				model.setUsertel(rs.getString("usertel"));
				model.setHeaderimage(rs.getString("headerimage"));
				model.setId(rs.getInt("id"));
			}
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		helper.close();
		return model;
	}
	
}
